import { ref, computed } from 'vue'
import { defineStore } from 'pinia'


export const useStore = defineStore('tasklist', () => {
  let tasklist = ref([])
  let i = ref(0)

let finish=computed(()=>{
  return tasklist.value.filter((item)=>{
    return item.status
  }).length
}) 
  let add = (payload) => {
    // console.log(payload);
    tasklist.value.push({ id: ++i.value, name: payload, status: false })
  }
  let changeStatus = (payload) => {
    // console.log(payload);
    let index = tasklist.value.findIndex((item) => {
      return item.id == payload
    })
    tasklist.value[index].status = !tasklist.value[index].status
  }
  let remove=(payload) => {
    // console.log(payload);
    let index = tasklist.value.findIndex((item) => {
      return item.id == payload
    })
    tasklist.value.splice(index,1)
  }
  return { tasklist,finish, add, changeStatus, remove }
})
